from selenium import webdriver
import requests
import re



def catch_text(animal_name):

    path='https://baike.baidu.com/item/'+animal_name
    headers = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3)'}

    try:
        response = requests.get(path,headers=headers)
        response.encoding = response.apparent_encoding
        if response.status_code//100==4:
            print('无法访问404')
    except:
        print('请求失败')

    text = response.text
    reslut = re.search(r'<meta name="description" content="(.*?)">',text)
    msg = reslut.group(1)
    return  msg
